@extends('layouts.app')

@section('title', '编辑首页内容')

@section('css-write')
<style type="text/css">
	.toutiaocontent,.searchshop{
		margin-bottom:20px;
	}
	.loadlbBackground,.loadfkBackground{
		max-width: 350px;
	    display: block;
	    margin: 15px;
	    max-height: 300px;
	}
</style>
@endsection

@section('content-fluid')

<h3 class="page-title">内容编辑</h3>
<form action="/todayNewsAdd" method="post" id="toutiaoFrom">
	<div class="row" style="padding:20px 0;">
		<div class="col-xs-4 toutiao">
			<label class="control-label">修改头条内容</label>
			<input type="text" name="model_toutiao" value="" class="form-control toutiaocontent hide" placeholder="头条内容" delmsg="false">
			@foreach($content['toutiao'] as $v)
			<input type="text" name="toutiaocontent[]" value="{{$v}}" class="form-control toutiaocontent" placeholder="头条内容" delmsg="false">
			@endforeach
		</div>
		<div class="col-xs-4" style="padding-top:25px;">
			<button type="button" class="btn btn-default inserttoutiao" ><i class="fa fa-plus-square"></i>  添加</button>
		</div>
	</div>
	<div class="row" style="padding-top:10px;">
		<div class="col-xs-4">
			<input type="submit" class="btn btn-primary btn-toastr center-block save_toutiao" value="保存头条内容"> 
		</div>
	</div>
</form>
<div class="row" style="padding:20px 0;">
	<div class="col-xs-12">
		<label class="control-label" style="display: block;">轮播图</label>
		<div class="col-xs-4" style="margin-top: 20px;">
			<button type="button" class="btn btn-default" style="margin-bottom:20px;" data-toggle="modal" data-target="#exampleModal" data-whatever="0"><i class="fa fa-plus-square"></i>  添加轮播图</button>
	        <div id="myCarousel" class="carousel slide">
				<!-- 轮播（Carousel）指标 -->
				<ol class="carousel-indicators">
					@foreach($content['lunbo'] as $k=>$v)
					<li data-target="#myCarousel" data-slide-to="{{$k}}" class="item_active"></li>
					@endforeach
				</ol>   
				<!-- 轮播（Carousel）项目 -->
				<div class="carousel-inner">
					@foreach($content['lunbo'] as $v)
					<div class="item" data-toggle="modal" data-target="#exampleModal" data-whatever="{{$v['shop_id']}}/{{$v['id']}}" data-url="{{$v['url']}}" data-type="{{$v['type']}}">
						<img src="{{$v['filePath']}}" alt="First slide">
					</div>
					@endforeach
				</div>
				<!-- 轮播（Carousel）导航 -->
				<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
					<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
					<span class="sr-only">Previous</span>
				</a>
				<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
					<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
					<span class="sr-only">Next</span>
				</a>
			</div>
	    </div>
	</div>
</div>

<form action="/edit/app/cardimg" method="post" enctype="multipart/form-data" id="defaultCardForm">
	<div class="row" style="padding:20px 0;">
		<div class="col-xs-12">
			<label class="control-label" style="display: block;">默认饭卡图</label>
			<div class="col-xs-4" style="margin-top: 20px;">
		        <div id="myCarousel" class="carousel slide">
					<img src="{{$content['card_default_img']}}" class="loadfkBackground">
		            <input type="file" name="fanka">
				</div>
		    </div>
		</div>
		<div class="col-xs-2" style="margin-top:20px;">
			<input type="submit" class="btn btn-primary btn-toastr center-block savedefaultimg" value="保存图片"> 
		</div>
	</div>
</form>

<div class="row" style="padding:20px 0;">
	<div class="col-xs-12">
		<label class="control-label" style="display: block;">分享背景图（827*1509px）</label>
		<div class="col-xs-2" style="margin-top: 20px;">
			<img src="/img/share_c.jpg" class="loadfkBackground">
            <input type="file" name="fanka">
	    </div>
	    <div class="col-xs-2" style="margin-top: 20px;">
			<img src="/img/share_b.jpg" class="loadfkBackground">
            <input type="file" name="fanka">
	    </div>
	    <div class="col-xs-2" style="margin-top: 20px;">
			<img src="/img/share_a.jpg" class="loadfkBackground">
            <input type="file" name="fanka">
	    </div>
	</div>
</div>
<form action="/edit/user/agreement" method="post" id="useragrFrom">
	<div class="row" style="padding:20px 0;">
		<div class="col-xs-12">
			<label class="control-label" style="display: block;">用户服务协议</label>
			<div id="div3" placeholder="介绍卡券特权优惠" alt="介绍卡券特权优惠">{!!$user_agr!!}</div>
			<input type="hidden" name="content" id="desc" onchange="descChange(this)" value="{{$user_agr}}">
		</div>
		<div class="col-xs-2" style="margin-top:20px;">
			<input type="submit" class="btn btn-primary btn-toastr center-block saveuseragreement" value="保存内容"> 
		</div>
	</div>
</form>
<!-- END BASIC TABLE -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="exampleModalLabel">设置内容</h4>
      </div>
      <form action="/broadcastEdit" method="post" enctype="multipart/form-data" id="lbtform">
	      <div class="modal-body">
	          <div class="form-group">
	            <label for="message-text" class="control-label">跳转位置:</label>
	            <label class="fancy-radio">
	          		<input type="radio" name="targettype" value="show" checked="checked">
					<span><i></i>仅展示</span>
				</label>
	          	<label class="fancy-radio">
	          		<input type="radio" name="targettype" value="url">
					<span><i></i>网页地址</span>
				</label>
				<label class="fancy-radio searchshop">
	          		<input type="radio" name="targettype" value="shop" checked="checked">
					<span><i></i>店铺列表</span>
				</label>
				<div class="hiddblock">
		            <label for="message-text" class="control-label shop-phone">推荐店铺:</label>
		            <input class="form-control searchshop" AUTOCOMPLETE="off" id="message-text" type="text" name="shop_tel" placeholder="填写店铺的账号，手机号">
		            <div class="shop-info hide">
			            <hr>
				            <p class="lead"><span class="label label-info shop-info-name"></span></p>
				            <p class="shop-info-address"></p>
			            <hr>
		            </div>
	            </div>
	            
	            <label for="message-text" class="control-label">图片:</label>
	            <img src="" class="loadlbBackground">
	            <input type="file" name="lbt">
	          </div>
	          <input type="hidden" name="shop_id" value="">
	          <input type="hidden" name="shop_name" value="">
	          <input type="hidden" name="broadcast_id" value="">
	          <input type="hidden" name="action" value="">
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default close-modal" data-dismiss="modal"></button>
	        <button type="submit" class="btn btn-primary confirmlbt"></button>
	      </div>
      </form>
    </div>
  </div>
</div>
@endsection

@section('js-import')
<script type="text/javascript" src="{{config('app.inlet_src')}}/a/js/homeediting.js"></script>
<script type="text/javascript" src="https://unpkg.com/wangeditor@3.1.1/release/wangEditor.min.js"></script>
<script type="text/javascript">
	var E = window.wangEditor
	var editor = new E('#div3')
	editor.customConfig.uploadImgServer = '/coupon/upload'  // 上传图片到服务器
	editor.customConfig.uploadImgHeaders = {
	    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
	};
	editor.customConfig.uploadFileName = 'images';
	var $text1 = $('#desc');
	editor.customConfig.onchange = function (html) {
        // 监控变化，同步更新到 textarea
        $text1.val(html)
    }
    function descChange(this_){
    	editor.txt.html(document.getElementById("desc").value);
    }
    // 自定义菜单配置
    editor.customConfig.menus = [
        'head',  // 标题
	    'underline',  // 下划线
	    'strikeThrough',  // 删除线
	    'foreColor',  // 文字颜色
	    'backColor',  // 背景颜色
	    'link',  // 插入链接
	    'list',  // 列表
	    'justify',  // 对齐方式
	    'emoticon',  // 表情
	    'image',  // 插入图片
	    'video',  // 插入视频
	    'undo',  // 撤销
	    'redo',  // 重复
	    'code'
    ]
	editor.create()

	var SendParam = {
		'dataType':'json',
		'beforeSubmit':toutiaoBefore,
		'success':toutiaoResponse,
		'error':toutiaoError,
	};

	function toutiaoBefore(formData, jqForm, options){
		
	}

	function toutiaoResponse(response) {
		if(response.success){
			toastr.success(response.message);
		}else{
			toastr.error('修改失败，请联系开发人员！');
		}
	}

	function toutiaoError(XMLHttpRequest, textStatus, errorThrown) {

		if(XMLHttpRequest.status==422){

			var RegError = XMLHttpRequest.responseJSON.errors;

			for(var o in RegError){

				for (var i = 0; i < RegError[o].length; i++) {

					toastr.error(RegError[o][i]);

				}

			}

		}

	}

	ajaxForm_('#useragrFrom', SendParam);
	ajaxForm_('#defaultCardForm', SendParam);
</script>
@endsection
